package pers.wensheng.patterns.creator_pattern.builder_pattern.simple_usage;

/**
 * 手机类
 */
public class Phone {

    private String cpu;
    private String screen;
    private String memory;
    private String mainboard;
    //私有构造方法
    private Phone(Builder builder){
        this.cpu=builder.cpu;
        this.screen=builder.screen;
        this.memory=builder.memory;
        this.mainboard=builder.mainboard;

    }
    /**
     * 定义一个静态的内部类，进行组件的构建。
     * 把指挥者类和抽象建造者进行结合，甚至直接可以用一个内部类。
     */
    public static final class Builder{
        private String cpu;
        private String screen;
        private String memory;
        private String mainboard;

        public Builder cpu(String cpu){
            this.cpu =cpu;
            return this;
        }
        public Builder screen(String screen){
            this.screen = screen;
            return this;
        }
        public Builder memory(String memory){
            this.memory = memory;
            return this;
        }
        public Builder mainboard(String mainboard){
            this.mainboard = mainboard;
            return this;
        }

        /**
         * 使用构建者创建phone对象
         * @return
         */
        public Phone builder(){
            return  new Phone(this);
        }
    }

    @Override
    public String toString() {
        return "Phone{" +
                "cpu='" + cpu + '\'' +
                ", screen='" + screen + '\'' +
                ", memory='" + memory + '\'' +
                ", mainboard='" + mainboard + '\'' +
                '}';
    }
}
